package com.ruoyi.merchant.utils;

import java.security.SecureRandom;

public class RandomNumberGenerator {

    // 生成指定长度的随机数字字符串(数字验证码)
    public static String generateRandomDigits(int length) {
        if (length < 0) {
            throw new IllegalArgumentException("长度必须是正整数");
        }

        SecureRandom random = new SecureRandom();
        StringBuilder sb = new StringBuilder(length);

        // 确保验证码第一位不为0
        sb.append(random.nextInt(9) + 1);

        // 生成后续数字
        for (int i = 1; i < length; i++) {
            sb.append(random.nextInt(10));
        }

        return sb.toString();
    }

}
